<?php
/**
 * Dependency Operations listener
 *
 * PHP version 5
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id:$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
require_once 'W/Dependency/Listener/Abstract.php';
/**
 * Dependency Operations listener
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
class W_Dependency_Listener_Operators extends W_Dependency_Listener_Abstract
{
    private $count = 0;

    /**
     * List all expected events
     *
     * @return W_Dependency_Listener_Interface
     */
    public function listExpectedEvents()
    {
        return array_merge(parent::listExpectedEvents(),
            array('enterOperator','exitOperators'));
    }

    /**
     * Processes the specified event
     *
     * @param string $type the event type to process
     * @param array  $data the optional data of the event
     *
     * @return array list of optional additional files to analyze
     *
     * @throws RuntimeException if an error occured
     */
    public function processEvent($type,$data=null)
    {
        $items = parent::processEvent($type,$data);

        switch($type) {
            case 'enterOperator':
                W_W::con()->updateLine(' [Operating] Processing ',(string)$data['operator'],'...');
                $this->count++;
                break;
            case 'exitOperators':
                if (0 < $this->count) {
                    W_W::con()->updateLine(' [Operating] '.$this->count.' operator'.(1 < $this->count ? 's' : '').' executed.'.PHP_EOL);
                }
                break;
        }

        return $items;
    }
}